import { Component, OnInit, OnDestroy,ChangeDetectorRef,ChangeDetectionStrategy,ViewChild,ElementRef, Inject, PLATFORM_ID, HostListener } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd/message';
import { FormBuilder, FormGroup, Validators,FormControl } from '@angular/forms';
import { HttpClient } from '@angular/common/http';
import { NzModalRef, NzModalService } from 'ng-zorro-antd/modal';
import { NzInputNumberModule } from 'ng-zorro-antd/input-number';
import { isPlatformBrowser } from '@angular/common';
import * as $ from "jquery";
import { UtilComponent } from "../home/util.component";
import screenfull from 'screenfull';
@Component({
  selector: 'u03op40online',
  templateUrl: './u03op40online.component.html',
  styleUrls: ['./u03op40online.component.css'],
  changeDetection:ChangeDetectionStrategy.OnPush
})
export class TwounitsComponent implements OnInit {
  // @ViewChild('myInput') myInput: ElementRef;
  title = '轴瓦读码识别防错程序';
  functionmenu = false;
  showlog = false;
  qrCodeMessage = false;
  hlqcPage = false;
  CloseHLQC = false;
  hlPage = false;
  rkPage = false;
  selectJX = false;
  plcError = false;
  isShow = false;
  greenButton = "background: #10B568; box-shadow: inset -4px 4px 6px rgba(0, 0, 0, 0.2); border-radius: 2px";
  redButton = "background: #941010; box-shadow: inset -4px 4px 6px rgba(0, 0, 0, 0.2); border-radius: 2px";
  blueButton = "background: #539be2; box-shadow: inset -4px 4px 6px rgba(0, 0, 0, 0.2); border-radius: 2px";
  blackButton = "background: #051E48; box-shadow: inset -4px 4px 6px rgba(0, 0, 0, 0.2); border-radius: 2px";
  yellowButton = "background: #FFAB00; box-shadow: inset -4px 4px 6px rgba(0, 0, 0, 0.2); border-radius: 2px";
  brownButton = "background: #941010; box-shadow: inset -4px 4px 6px rgba(0, 0, 0, 0.2); border-radius: 2px";
  defaultButton = "background: #c2ccd0; box-shadow: inset -4px 4px 6px rgba(0, 0, 0, 0.2); border-radius: 2px";
  changeSkuItems = null;
  private timer:any;
  public list:any;
  handleCancel(): void {
    console.log('Button cancel clicked!');
    this.functionmenu = false;
    this.showlog = false;
    this.cleanall = false;
    this.clean = false;
    this.Warehousing = false;
    this.Increaseinventory = false;
    this.cleanallok =false;
    this.RequestConfirm = false;
    this.RequestConfirmjx = false;
    this.qrCodeMessage = false;
    this.hlqcPage = false;
    this.hlPage = false;
    this.rkPage = false;
    this.selectJX = false;
    this.CloseHLQC = false;
    //销毁localStorage
    localStorage.clear();
  }
  constructor(private message: NzMessageService,
    private fb: FormBuilder,
    public http:HttpClient,
    private ref: ElementRef,
    private cd: ChangeDetectorRef,
    private modal: NzModalService,
    @Inject(PLATFORM_ID) private platformId: Object
    ) {
    }
    qrMessageL1 = {
    sku:"",
    Box:"",
    qty:50
    }
    qrMessageL2 = {
      sku:"",
      Box:"",
      qty:50
      }
      qrMessageL3 = {
        sku:"",
        Box:"",
        qty:50
        }
        qrMessageL4 = {
          sku:"",
          Box:"",
          qty:50
          }
  //销毁组件时清除定时器
  ngOnDestroy(){
    if(this.timer){
    clearInterval(this.timer);
    }
    }
  ngOnInit(): void {
    this.timer=setInterval(()=>{
      this.wbmessages();
      this.queryHL();
    },2000)
    this.getModel();
    //this.wbmessages();
  }
  // ngAfterViewInit():void {
  //   if (isPlatformBrowser(this.platformId)){
  //     this.myInput.nativeElement.focus();
  //   }
  // }

  
  bltitle = "补料";
  unit = "三单元线上料仓"
  left = "曲轴轴瓦A"
  right = "曲轴轴瓦B"
  leftName = ""
  rightName = ""
  N0= ""
  N1= ""
  N2= ""
  N3= ""
  N4= ""
  N5= ""
  N6= ""
  N7= ""
  kxms2 = ""
  clearN() :any{
    this.N0= ""
    this.N1= ""
    this.N2= ""
    this.N3= ""
    this.N4= ""
    this.N5= ""
    this.N6= ""
    this.N7= ""
  }
  public  wbmessages() : any {
    //获取物料数量和日志
    var url="was/services/rest/WasService/InventoryQueryTHA";
    this.http.post(url, {"Container": "all","status": "2"})
      .subscribe((response)=>{
        this.list=response;
        //加载页面配置
        var config = this.list.UIMessage[0];
        this.unit = config.unit;
        this.title = config.title;
        // let unitDom:any = document.getElementById("unit");
        // unitDom.innerHTML = config.unit;
        this.left = config.locationName[0].name;
        this.right = config.locationName[1].name;
        this.leftName = this.list.ExistSkuNameA1;
        this.rightName = this.list.ExistSkuNameA2;
        //闪烁正在开箱的料箱取货数量
        switch(this.list.OpenBox){
          case 1:
            this.clearN()
            this.N0 = this.list.OpenNum;
            break;
            case 2:
              this.clearN()
              this.N1 = this.list.OpenNum;
              break;
              case 3:
                this.clearN()
                this.N2 = this.list.OpenNum;
                break;
                case 4:
                  this.clearN()
                  this.N3 = this.list.OpenNum;
                  break;
                  case 5:
                    this.clearN()
                    this.N4 = this.list.OpenNum;
                    break;
                    case 6:
                      this.clearN()
                      this.N5 = this.list.OpenNum;
                      break;
                      case 7:
                        this.clearN()
                        this.N6 = this.list.OpenNum;
                        break;
                        case 8:
                          this.clearN()
                          this.N7 = this.list.OpenNum;
                          break;
                          default:
                            this.clearN()
        }
        //库存数量
        for( var i =0;i<8;i++){
          let nameDom:any = document.getElementById("A"+i);
          nameDom.innerHTML = this.list.data[i].Quantity;
          let colorDom:any = document.getElementById("color"+i);
          if(this.list.data[i].isLock){
            colorDom.style = this.defaultButton;
          }else{
            if(this.list.data[i].Color == "绿"){
              colorDom.style = this.greenButton;
            }else if(this.list.data[i].Color == "红"){
              colorDom.style = this.redButton;
            }else if(this.list.data[i].Color == "黑"){
              colorDom.style = this.blackButton;
            }else if(this.list.data[i].Color == "蓝"){
              colorDom.style = this.blueButton;
            }else if(this.list.data[i].Color == "褐"){
              colorDom.style = this.brownButton;
            }else if(this.list.data[i].Color == "黄"){
              colorDom.style = this.yellowButton;
            }else{
              colorDom.style = this.defaultButton;
            }
          }
        }
        //换料弹出框是否显示
        if(this.list.ChangeSku){
          if(!this.qrCodeMessage) this.qrCodeMessage = true;
          this.changeSkuItems = this.list.ChangeSkuItems;
          this.updateChangeSkuStyle();
        }
        //查看日志数据（100条）
        this.listOfData = this.list.logs;

        if(this.list.logs.length>0){
          let nameDom:any = document.getElementById("log0");
          nameDom.innerHTML = this.list.logs[0].Time+" " +this.list.logs[0].Message;
        }else{
          let nameDom:any = document.getElementById("log0");
          nameDom.innerHTML = "暂无日志数据";
        }
        var messagelist:any;//颜色按字分开后存放在colorlist中
        if(this.list.MQdata!=null){
          messagelist=this.list.MQdata.split("@")
        var colorlist:any;
        colorlist=messagelist[0].split("&")
        //开箱模式
        // let kxms:any = document.getElementById("kxms");
        // kxms.innerHTML = messagelist[2];
        //连杆上出库颜色
        let phzzw:any = document.getElementById("phzzw");
        var phzzwlist:any;
        phzzwlist = colorlist[0].split("")
        var phzdiv:any = "";//用于存放改变颜色后的“代码”,如<span style="***">红</span><span style="***">蓝</span>
        for(var a=0;a<phzzwlist.length;a++){
          phzdiv=phzdiv+"<div style='color: " + UtilComponent.getColor16ByText(phzzwlist[a])
            + ";display:inline-block;'>" + phzzwlist[a] + "</div>";
        }
        phzzw.innerHTML = phzdiv;
        //连杆下出库颜色
        let qzzw:any = document.getElementById("qzzw");
        var qzzwlist:any;
        qzzwlist = colorlist[1].split("")
        var qzdiv:any = "";//用于存放改变颜色后的“代码”,如<span style="***">红</span><span style="***">蓝</span>
        for(var a=0;a<qzzwlist.length;a++){
          qzdiv = qzdiv + "<div style='color: " + UtilComponent.getColor16ByText(qzzwlist[a])
            + ";display:inline-block;'> " + qzzwlist[a] + " </div>";
        }
        qzzw.innerHTML = qzdiv;
        //条码信息
        var tmxxlist:any;
        tmxxlist = messagelist[1].split("&")
        var le = 0;
        if(tmxxlist.length>5){
          le = 5;
        }else{
          le = tmxxlist.length;
        }
        for(var i=0;i<le;i++){
          let tmxx:any = document.getElementById("tm"+i);
          tmxx.innerHTML = tmxxlist[i];
        }
        }

        this.cd.markForCheck();
      })
  }
  //功能选择菜单

  //入库和补料按钮是否可以点击
  rkan = false;
  blan = true;
  async dialog( local:string )//声明标识符
  {
    await this.request(local);
  }
  async request(local:string){
    this.blan = true;
    localStorage.site = local;
    var area="0";
    if(local=="0"||local=="1"||local=="2"||local=="3"){
      area="1"
    }else{
      area="2"
    }

    // var img = "<button>清仓</button>"
    // let rk:any = document.getElementById("qzzw");
    // var rkandiv:any = "";
    var url="was/services/rest/WasService/InventoryQueryTHA";
    this.http.post(url, {"Container": local,"status": "1","area":area})
      .subscribe((response)=>{
        var skumessage:any =response;
        if(!skumessage.data[0].isLock){
          localStorage.Quantity = skumessage.data[0].Quantity
          localStorage.existsku = skumessage.existsku
          this.dqwl=skumessage.existsku
          localStorage.color = skumessage.data[0].Color
          localStorage.skuName = skumessage.name
          //控制按钮是否可用
          // if(localStorage.Quantity == 0){
          //   this.rkan = false;
          //   this.blan = true;
          //   this.cd.markForCheck();
          // }else{
          //   this.rkan = true;
          //   this.blan = false;
          //   this.cd.markForCheck();
          // }
          this.functionmenu = true;
          this.cd.markForCheck();
        }
        
    })

  }
  //日志查看
  loginfo() :void{
    this.showlog = true;
  }
  //日志模拟数据
  listOfData: ItemData[] = [];
    // 重新请求按钮处理
    RequestConfirm = false;
    RequestConfirmjx = false;
  Rerequested(): void {
    this.RequestConfirm = true;
  }
  RequestConfirmOK():void{
    //请求数据url
    const id = this.message.loading('重新请求中，请稍后..', { nzDuration: 0 }).messageId;
    var url="was/services/rest/WasService/reGetZNLC";
    this.http.post(url, {"gwh": "U03-OP040","sbbh":"SB0304005"})
      .subscribe((response)=>{
        var list:any=response;
        if(list.message=="重新请求成功"){
          setTimeout(() => {
            this.message.remove(id);
            this.message.success("成功");
          }, 1000);
        }else{
          setTimeout(() => {
            this.message.remove(id);
            this.message.error("失败");
          }, 1000);
        }
        this.RequestConfirm = false;
        this.cd.markForCheck();
    })
  }
  //全部清仓
  cleanall = false;
  cleanAll(): void {
    this.cleanall = true;
  }
  QRForm!: FormGroup;

  
  //换料测试按钮
  changeMode(): void{
    this.qrCodeMessage = true;
  }
  //换料二维码提交
  commitQR():void{
    // 提交内容检查
    let warnMsg = "";
    let isEmpty = true;
    if(this.qrMessageL1.Box != "" || this.qrMessageL1.sku != "") {
      isEmpty = false;
      if(this.qrMessageL1.Box != "" && this.qrMessageL1.sku == "") warnMsg += "第一列料仓二维码为空;";
      if(this.qrMessageL1.Box == "" && this.qrMessageL1.sku != "") warnMsg += "第一列料盒二维码为空;";
    }
    if(this.qrMessageL2.Box != "" || this.qrMessageL2.sku != "") {
      isEmpty = false;
      if(this.qrMessageL2.Box != "" && this.qrMessageL2.sku == "") warnMsg += "第二列料仓二维码为空;";
      if(this.qrMessageL2.Box == "" && this.qrMessageL2.sku != "") warnMsg += "第二列料盒二维码为空;";
    }
    if(this.qrMessageL3.Box != "" || this.qrMessageL3.sku != "") {
      isEmpty = false;
      if(this.qrMessageL3.Box != "" && this.qrMessageL3.sku == "") warnMsg += "第三列料仓二维码为空;";
      if(this.qrMessageL3.Box == "" && this.qrMessageL3.sku != "") warnMsg += "第三列料盒二维码为空;";
    }
    if(this.qrMessageL4.Box != "" || this.qrMessageL4.sku != "") {
      isEmpty = false;
      if(this.qrMessageL4.Box != "" && this.qrMessageL4.sku == "") warnMsg += "第四列料仓二维码为空;";
      if(this.qrMessageL4.Box == "" && this.qrMessageL4.sku != "") warnMsg += "第四列料盒二维码为空;";
    }
    if(isEmpty) warnMsg += "未输入内容;"
    if(warnMsg != "") {
      let qr:any = document.getElementById("qrResult");
      qr.innerHTML = warnMsg;
      return;
    }

    let listQR = [this.qrMessageL1,this.qrMessageL2,this.qrMessageL3,this.qrMessageL4]
    console.log(listQR);
    var url="was/services/rest/WasService/QRCode";
    let that = this;
    this.http.post(url, {"StyleNo": "3A","qrCodeMessage":listQR})
      .subscribe((response)=>{
        var list:any=response;
        let qr:any = document.getElementById("qrResult");
        qr.innerHTML = list.message;
        if(list.msgType == "0") {
          // 换料成功，1秒后自动关闭弹窗
          this.setNull();
          this.changeSkuItems = null;
          this.updateChangeSkuStyle();
          setTimeout(()=>{
            that.qrCodeMessage = false;
          },1000)
        }
        this.cd.markForCheck();
      })

  }
  setNull():void{
    this.qrMessageL1.Box = ""
    this.qrMessageL1.sku = ""
    this.qrMessageL1.qty = 50
    this.qrMessageL2.Box = ""
    this.qrMessageL2.sku = ""
    this.qrMessageL2.qty = 50
    this.qrMessageL3.Box = ""
    this.qrMessageL3.sku = ""
    this.qrMessageL3.qty = 50
    this.qrMessageL4.Box = ""
    this.qrMessageL4.sku = ""
    this.qrMessageL4.qty = 50
    var qr:any = document.getElementById("qrResult");
    qr.innerHTML = "";
    this.cd.markForCheck();
  }
  nextFocus(x:any, y:any) : void {
    let maxX = 4;//列数最大值
    let maxY = 3;//行数最大值
    if(y < maxY) {// 不需要换列
      y++;
    } else {// 需要移动到下一列
      y = 1;
      x = x == maxX ? 1 : ++x;
    }
    let post = (x - 1) * maxY + y - 1;
    // inputs的顺序为按列顺序
    let inputs = document.getElementsByTagName("input");
    // 找到第一个可用的输入框并设置焦点
    for(let i = post; i<maxX * maxY; i++){
      if(!inputs[i].disabled) {
        inputs[i].focus();
        return;
      }
    }
  }
//  focusNextInput(thisInput: this | HTMLInputElement) {
//   var inputs = document.getElementsByTagName("input");
//   for(var i = 0;i<inputs.length;i++){
//       // 如果是最后一个，则焦点回到第一个
//       if(i==(inputs.length-1)){
//           inputs[0].focus();
//           break;
//       }else if(thisInput == inputs[i]){
//           inputs[i+1].focus();
//           break; //不加最后一行eles就直接回到第一个输入框
//       }else { //最后的eles是添加的表单提交方法(如果想实现登陆，可以写入登陆方法)
//           console.log("最后一个")
//       }
//   }
// }
  //清仓成功确定按钮
  cleanallok = false;

  cleanAllok(): void {
    var that=this;
    this.cleanall = false;
    this.cleanallok = true;
    var url="was/services/rest/WasService/InventoryClean";
    this.http.post(url, {"Container": "All","status": "2"})
      .subscribe((response)=>{
        var list:any=response;
        if(list.message=="成功"){
          setTimeout(() => {
            that.cleanallok = false;
            console.log('1', that.cleanallok);
            this.cd.markForCheck();
          }, 1500);
        }
    })
  }
  //手动开箱
  manual(): void {
    var url="was/services/rest/WasService/ManualThreeA";
    this.http.post(url, {"Code": 1})
      .subscribe((response)=>{
    })
  }
  //单独清仓按钮
  clean = false;
  cleanThis(): void {
    this.functionmenu = false;
    this.clean = true;
  }
  //单独清仓确定按钮
  cleanok(): void {
    var url="was/services/rest/WasService/InventoryClean";
    this.http.post(url, {"Container": localStorage.site,"status": "1"})
      .subscribe((response)=>{
        var list:any=response;
        if(list.message=="成功"){
          //刷新数据
          localStorage.clear();
        }
    })
    this.clean = false;
  }
  //入库
  Warehousing = false;
  validateForm!: FormGroup;

  addware(): void{
    this.functionmenu = false;
    this.Warehousing = true;
    this.validateForm = this.fb.group({
      // Code: [null],
      Sku: [null, [this.inConfirmValidator]],
      Quantity: [50, [Validators.required]],
      Container:[localStorage.site]
    });
  }
  //入库确定按钮
  warehousingok(){
    //for循环是点击确定按钮时如果输入不符合规范进行提示
    for (const key in this.validateForm.controls) {
      if (this.validateForm.controls.hasOwnProperty(key)) {
        this.validateForm.controls[key].markAsDirty();
        this.validateForm.controls[key].updateValueAndValidity();
      }
    }
    if (this.validateForm.valid) {
      var url="was/services/rest/WasService/InWorkBin";
      this.http.post(url, this.validateForm.value)
        .subscribe((response)=>{
          var list:any=response;
          if(list.message=="成功"){
            //刷新数据
            localStorage.clear();
          }
      })
      //关闭入库窗口
      this.Warehousing = false;
    }
  }
  // codeChange():void{
  //   var a = $("#Code").val;
  //   console.log(a+"1111")
  //   $("#Sku").val = a;
  // }
  //入库验证
  inConfirmValidator = (control: FormControl): { [s: string]: boolean } => {
    var insku = localStorage.existsku
    if (!control.value) {
      return { error: true, required: true };
    } else if (insku != "null") {
      if(control.value != insku){
        return { confirm: true, error: true };
      }
    }
    return {};
  };
  //补料

  Increaseinventory = false;
  addinventory(): void{
    console.log(localStorage.existsku)
    this.bltitle = "补料";
    this.functionmenu = false;
    this.Increaseinventory = true;
    this.validateForm = this.fb.group({
      // Code: [null],
      Sku: [null, [this.confirmValidator]],
      Quantity: [50, [Validators.required]],
      Color:[localStorage.color],
      Container:[localStorage.site],
    });
  }
  //补料验证
  confirmValidator = (control: FormControl): { [s: string]: boolean } => {
    if (!control.value) {
      return { error: true, required: true };
    } else if (control.value !== localStorage.existsku) {
      return { confirm: true, error: true };
    }
    return {};
  };
  validateConfirmPassword(): void {
    setTimeout(() => this.validateForm.controls.name.updateValueAndValidity());
  }
  //补料确定按钮
  addMaterialok(){
    //for循环是点击确定按钮时如果输入不符合规范进行提示
    for (const key in this.validateForm.controls) {
      if (this.validateForm.controls.hasOwnProperty(key)) {
        this.validateForm.controls[key].markAsDirty();
        this.validateForm.controls[key].updateValueAndValidity();
      }
    }
    if (this.validateForm.valid) {
      var url="was/services/rest/WasService/AddWorkBin";
      this.http.post(url, this.validateForm.value)
        .subscribe((response)=>{
          var list:any=response;
          if(list.message=="成功"){
            //刷新数据
            localStorage.clear();
          }
      })
      //关闭补料窗口
      this.Increaseinventory = false;
    }
  }

  public codeChange(){
    var a = this.validateForm.value.Code
    if(a!=null){
      var b = a.slice(6)
    this.validateForm.patchValue({Sku: b})
    }
  }
  public clearQuantity(){
    this.validateForm.patchValue({Quantity: ''});
  }
  public clearSku(){
    this.validateForm.patchValue({Sku: ''});
  }
  public clearCode(){
    this.validateForm.patchValue({Code: ''});
  }
  Close():void{
    //const id = this.message.loading('重新请求中，请稍后..', { nzDuration: 0 }).messageId;
    var url="was/services/rest/WasService/closeBox";
    this.http.post(url, {"gwh": "U03-OP040","sbbh":"SB0304005"})
      .subscribe((response)=>{
        this.cd.markForCheck();
    })
  }
  //全屏
  //status = false;
  // private get sf(): screenfull.Screenfull {
  //   return screenfull as screenfull.Screenfull;
  // }

  // @HostListener('window:resize')
  // _resize(): void {
  //   this.status = this.sf.isFullscreen;
  // }

  // @HostListener('click')
  // // 触发全屏直接调用此方法
  // _click(): void {
  //   if (this.sf.isEnabled) {
  //     this.sf.toggle();
  //   }
  // }
  full() {
		if (screenfull.isEnabled) {
			screenfull.toggle();
		}
	}
  // 切换开箱模式（手动-》自动，自动-》手动）
  swtichUnpackingModel(): void {
    let url="was/services/rest/WasService/SwtichUnpackingModel";
    this.http.post(url, {"StyleNo": "3A"})
      .subscribe((response)=>{
        // let resp:any=response;
        // let kxms:any = document.getElementById("kxms");
        // if(resp.msgType == "自动"){
        //   kxms.style = 'color: #0ee70e';
        // }else{
        //   kxms.style = 'color: #fa2408';
        // }
        // this.kxms2 = resp.msgType;
        // let nameDom:any = document.getElementById("log0");
        // nameDom.innerHTML = resp.message;
        window.parent.location.reload();
        this.cd.markForCheck();
      })
      this.getModel();
  }
  //重置智能料仓任务和PLC连接
  resetZNLC(): void {
    let url="was/services/rest/WasService/resetZNLC";
    this.http.post(url, {"StyleNo": "3A"})
      .subscribe((response)=>{
        this.cd.markForCheck();
      })
  }
  getModel(): void {
    let url="was/services/rest/WasService/GetModel";
    this.http.post(url, {"StyleNo": "3A"})
      .subscribe((response)=>{
        let resp:any=response;
        if(resp.msgType == "自动"){
          this.isShow = true;
          // kxms.style = 'color: #0ee70e';
          // kxms.innerHTML = "自动";
        }else{
          // kxms.style = 'color: #fa2408';
          // kxms.innerHTML = "手动";
          this.isShow = false;
        }
        let nameDom:any = document.getElementById("log0");
        nameDom.innerHTML = resp.message;
        this.cd.markForCheck();
      })
  }
  updateChangeSkuStyle(): void {
    let column1:any = document.getElementById("column1");
    let column2:any = document.getElementById("column2");
    let column3:any = document.getElementById("column3");
    let column4:any = document.getElementById("column4");
    if(column1 == null || column2 == null || column3 == null || column4 == null) return;

    let columns = [column1, column2, column3, column4];
    let changeSkuItems:any = this.changeSkuItems;
    if(changeSkuItems == null || changeSkuItems.length == 0) {
      for(let i = 0; i < columns.length; i++) {
        let column:any = columns[i];
        column.style.color = "black";
        column.style.backgroundColor = 'white';
      }
    } else {
      // 根据changeSkuItems更新行样式
      for(let i = 0; i < changeSkuItems.length; i++) {
        //item.Sku、item.Box、item.Color、item.Container
        let item:any = changeSkuItems[i];
        let position:number = item.Container;
        let line:number =position % 4;
        let column:any = columns[line];
        if(item.Color == "黑") column.style.color = "white";
        else column.style.color = "black";
        column.style.backgroundColor = UtilComponent.getColor16ByText(item.Color);
      }
    }
  }
  //当前物料
  dqwl = "";
  //2022/6/13新增换料
  dqjx = "";
  hljx = "";
  sylhbm = "";
  ts = "";
  HLPageData = {
    Box:"",
    qty:50
    }
  clearBox():void{
    this.HLPageData.Box = "";
  }
  //清仓换料
  cleanAndChange():void{
    this.hlqcPage = false;
    this.hlPage = false;
    this.rkPage = false;
    this.selectJX = true;
  }
  //换料过程中关箱按钮
  hlqcPageButton():void{
    var url="was/services/rest/WasService/HLClose";
    this.http.post(url, {"gwh": "U03-OP040","sbbh":"SB0304005"})
      .subscribe((response)=>{
        this.cd.markForCheck();
    })
  }
  stopHLConfimButton():void{
    var url="was/services/rest/WasService/stopHLQC";
    this.http.post(url, {"gwh": "U03-OP040","sbbh":"SB0304005"})
      .subscribe((response)=>{
        this.cd.markForCheck();
    })
    this.CloseHLQC = false;
  }
  stopHlqcPageButton():void{
    this.CloseHLQC = true;
  }
  //换料任务数据定时查询
  queryHL():void{
    var url="was/services/rest/WasService/queryPageHLRK";
    this.http.post(url, {"gwh": "U03-OP040","sbbh":"SB0304005"})
      .subscribe((response)=>{
        var list:any = response;
        this.dqjx = list.oldJX;
        this.hljx = list.newJX;
        this.sylhbm = list.boxCode;
        if(list.qcpage){
          this.hlqcPage = true
        }else if(list.isHL&&list.rkpage){
          this.hlPage = true;
        }else if(!list.isHl&&list.rkpage){
          this.rkPage = true;
        }else{
          this.hlPage = false;
          this.rkPage = false;
          this.hlqcPage = false;
        }
        this.cd.markForCheck();
    })
  }
  //换料过程中扫码输入框
  inputScan():void{
    if(this.sylhbm.indexOf(this.HLPageData.Box+"；")!=-1){
      var url="was/services/rest/WasService/openBoxCode";
      this.http.post(url, {"gwh": "U03-OP040","sbbh":"SB0304005","box":this.HLPageData.Box})
      .subscribe((response)=>{
        var list:any = response;
        this.ts = list.message;
    })
    }else{
      this.ts = this.HLPageData.Box+"料盒与当前机型不匹配，请检查料盒是否正确"
    }
    this.cd.markForCheck();
  }
  //换料过程中提交按钮
  hlqcPageSubmitButton():void{
    if(this.HLPageData.Box!=""){
      var url="was/services/rest/WasService/submitBoxCode";
      this.http.post(url, {"gwh": "U03-OP040","sbbh":"SB0304005","box":this.HLPageData.Box,"quantity":this.HLPageData.qty})
      .subscribe((response)=>{
        var list:any = response;
        this.ts = list.message;
        this.clearBox()
        this.cd.markForCheck();
    })
    }else{
      this.ts = "请扫描物料编码"
    }
    //焦点
    let inputs = document.getElementsByTagName("input");
    // 找到第一个可用的输入框并设置焦点
    inputs[0].focus();
  }
  //换料过程中重发开箱指令按钮
  hlqcPageResendButton():void{
    if(this.HLPageData.Box !=""){
    this.inputScan();
    }else(
      this.ts = "请扫描料盒"
    )
  }
  //换料过程中重置按钮
  hlqcPageResetButton():void{
    this.clearBox()
    this.ts = "";
    //焦点
    let inputs = document.getElementsByTagName("input");
    // 找到第一个可用的输入框并设置焦点
    inputs[0].focus();
  }
  jxList:any;
  queryAllJX():void{
    this.selectJX = true;
    var url="was/services/rest/WasService/queryAllJX";
    this.http.post(url, {"gwh": "U03-OP040","sbbh":"SB0304005"})
      .subscribe((response)=>{
        this.jxList = response;
        this.cd.markForCheck();
    })
  }
  confirmjx = ""
  confirmJX(jx:any):void{
    this.confirmjx = jx;
    this.RequestConfirmjx = true;
  }
  changeJX(confirmjx:any):void{
    var url="was/services/rest/WasService/changeJX";
    this.http.post(url, {"gwh": "U03-OP040","sbbh":"SB0304005","jx":confirmjx})
      .subscribe((response)=>{
        var list:any = response;
        this.handleCancel();
        this.cd.markForCheck();
    })
  }
}
interface ItemData {
  Time: string;
  Message: string;
  MQMessage: string;
}

